package com.itheima.youdianda.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.youdianda.common.Result;
import com.itheima.youdianda.domain.YddAdvpos;
import com.itheima.youdianda.domain.YddLink;
import com.itheima.youdianda.service.YddLinkService;
import com.itheima.youdianda.mapper.YddLinkMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author YUAN
 * @description 针对表【ydd_link】的数据库操作Service实现
 * @createDate 2022-09-06 18:36:39
 */
@Service
public class YddLinkServiceImpl extends ServiceImpl<YddLinkMapper, YddLink>
        implements YddLinkService {

    @Override
    public Result linkList(Integer page, Integer limit, String type) {
        Page ipage = new Page(page, limit);

        LambdaQueryWrapper<YddLink> lqw = new LambdaQueryWrapper<>();
        lqw.eq(StrUtil.isNotBlank(type), YddLink::getType, type);//模糊

        ipage = page(ipage, lqw);

        //用map集合处理下参数
        Map<String, Object> map = new HashMap<>();
        map.put("data", ipage.getRecords());
        map.put("count",ipage.getTotal());
        map.put("totalPages",ipage.getPages());
        map.put("pageSize",ipage.getSize());
        map.put("currentPage",ipage.getCurrent());

        return Result.ok(map);
    }
}




